<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="https://cdn.bootcdn.net/ajax/libs/jquery/1.10.0/jquery.js"></script>
  <script>
    $(function () {
      $('.del-btn').on('click', function (e) {
        $.ajax({
          type: "DELETE",
          url: '/posts',
          data: $(this).data(),
          success: ()=>{
            window.location.reload()
          },
        });
      })
    })
  </script>
</head>

<body>
  <h1>帖子列表</h1>
  <button onclick="location.href='/posts/add'">添加</button>
  <ul>
    <% list.forEach(function(item){ %>
      <li><a href="/posts/<%=item.id%>"><%= item.name %></a> <button class="del-btn" data-id="<%=item.id%>">删除</button></li>
    <% }); %>
  </ul>
</body>

</html>
